<?php
$selectedId = $response->getAttribute("selectedId");
$inputName = $response->getAttribute("inputName");
$title = $response->getAttribute("title");
$types = $response->getAttribute("types");

function showOption($selectedId, $type, $level)
{
    echo "\t".'<option value="' . $type->getId() . '"' ;
    if ($selectedId == $type->getId()) echo ' selected="selected"' ;
    echo ' >' ;
    for($i=0; $i<$level*4; $i++) echo '&nbsp;' ;
    echo '- ' . $type->getNom() . '</option>' . "\n" ;
}

function displayOptions($selectedId, $type, $level=0)
{
    $children = $type->getChildren();
    showOption($selectedId, $type, $level);
    $newLevel = $level + 1 ;
    foreach ($children as $child) {
        displayOptions($selectedId, $child, $newLevel);
    }
}

if ($types != null) {
?>
<span class="label">
    <span class="titre"><?php echo $title ; ?></span>
    <select class="firstInput" name="<?php echo $inputName ; ?>">
        <option value=""></option>
        <?php
        foreach ($types as $type) {
            displayOptions($selectedId, $type, 0);
        }
        ?>
    </select>
</span>
<?php 
} else {
?>
<input
    type="hidden"
    name="<?php echo $inputName ; ?>"
    value="<?php echo $typeId ; ?>" />
<?php
}
